/*
 * mox.h
 *
 *  Created on: Jul 11, 2010
 *      Author: jmonk
 */

#ifndef MOX_H_
#define MOX_H_

#ifndef NULL
#define NULL (0)
#endif

#ifndef __XC__
#include <xccompat.h>
#include "mox_compat.h"
#endif
#define S_MALLOC (0xf0f0f00f)
#define S_FREE   (0x0f0f0ff0)

#define THD_START_CORE 0
#define THD_START_NAME "SHTEST1"
#define THD_START_FUNC app_start_shell

#define SLAVE_WAIT_DELAY 100000
#define NUM_CORES 4
#define MAX_THDS 32
#define MASTER_CORE 0

#define MSG_TYPE	 (0xf00)
#define SUCCESS		 (0x000)

#define STORAGE_START 	((void*)1)
#define STORAGE_CORE 	(0)
#define STORAGE_STRUCT 	(module_flash)
#define STORAGE_NAME	"MFLASH1"

#ifndef __XC__
#define schanend chanend
#define uchanend chanend
#define REF(x) *x
#else
#define schanend streaming chanend
#define uchanend unsigned
#define REF(x) &x
#endif


/*
//MOX Signals
typedef enum {
	SIG_MSG=0x100,
	SIG_KILL,
	SIG_READY,
	SIG_IFREE,
	SIG_OFREE,
	SIG_ICONN,
	SIG_OCONN,
	SIG_IDISC,
	SIG_ODISC,
	SIG_NONE,
	SIG_ACK,
	SIG_NACK
} sig_msg_t;

//MOX Messages
typedef enum {
	MOX_MSG=0x200,
	MOX_REQ_MOD,
	MOX_REQ_THD,
	MOX_REQ_MOD_ID,
	MOX_REQ_THD_ID,
	MOX_COM_CMP,
	MOX_ACK,
	MOX_CMD,
	MOX_OOM,
	MOX_ABRT,
	MOX_INVLD_ARG,
	MOX_CREATE_TH,
	MOX_INIT_CRTH,
	MOX_UPDATE,
	MOX_NACK
} mox_msg_t;
*/
//MOX CMDs
typedef enum {
	LOG_UPDATE=0x10,
	CHAN_CREATE_LOC,
	CHAN_CREATE_REM,
} mox_cmd_t;

void delay_us(int delay);

typedef struct {
	int slave_unrespond[NUM_CORES];
	unsigned thd_cnt;
	char thd_core[MAX_THDS];
	unsigned frame;
#ifndef __XC__
	chanend chan_mox[NUM_CORES];
	struct system_log *log;
	struct mox_storage *storage;
	struct mox_cfg_state *cfg;
	struct mox_rthd *running_thds;
#else
	unsigned chan_mox[NUM_CORES];
	unsigned log;
	unsigned storage;
	unsigned cfg;
	unsigned running_thds;
#endif
} mox_master_state;

#include "mox_comm.h"

typedef struct mox_cfg_state {
	int cfg;
} mox_cfg_state;

#ifdef __XC__
void delay_us(int delay);
#endif

#include "mox_master_c.h"
#include "mox_master_xc.h"

#endif /* MOX_H_ */
